#include <iostream>
#include <stdlib.h>
#include "Matrix.h"
using namespace std;

int** Addition(int a, int b, int c, int d, int e, int f,int g, int h)
{
int** firstMatrix = new int*[2];
for(int i = 0; i < 2; ++i)
    firstMatrix[i] = new int[2];

int** secondMatrix = new int*[2];
for(int j = 0; j < 2; ++j)
    secondMatrix[j] = new int[2];

int** result = new int*[2];
for(int k = 0; k < 2; ++k)
    result[k] = new int[2];

int c1, k1, d1;
	
firstMatrix[0][0]=a;
firstMatrix[0][1]=b;
firstMatrix[1][0]=c;
firstMatrix[1][1]=d;

secondMatrix[0][0]=e;
secondMatrix[0][1]=f;
secondMatrix[1][0]=g;
secondMatrix[1][1]=h;

for ( c1 = 0 ; c1 < 2 ; c1++ )
{
      for ( d1 = 0 ; d1 < 2 ; d1++ )
          result[c1][d1] = firstMatrix[c1][d1] + secondMatrix[c1][d1];
}



for ( c1 = 0 ; c1 < 2 ; c1++ )
{
  for ( d1 = 0 ; d1 < 2 ; d1++ )
     cout<<result[c1][d1]<<"   ";
cout<<endl;
}

return result;
}

int** Subtract(int a, int b, int c, int d, int e, int f,int g, int h)
{

int** firstMatrix = new int*[2];
for(int i = 0; i < 2; ++i)
    firstMatrix[i] = new int[2];

int** secondMatrix = new int*[2];
for(int j = 0; j < 2; ++j)
    secondMatrix[j] = new int[2];

int** result = new int*[2];
for(int k = 0; k < 2; ++k)
    result[k] = new int[2];

int c1, k1, d1;
	
firstMatrix[0][0]=a;
firstMatrix[0][1]=b;
firstMatrix[1][0]=c;
firstMatrix[1][1]=d;

secondMatrix[0][0]=e;
secondMatrix[0][1]=f;
secondMatrix[1][0]=g;
secondMatrix[1][1]=h;

for ( c1 = 0 ; c1 < 2 ; c1++ )
      for ( d1 = 0 ; d1 < 2 ; d1++ )
         result[c1][d1] = firstMatrix[c1][d1] - secondMatrix[c1][d1];

for ( c1 = 0 ; c1 < 2 ; c1++ )
{
  for ( d1 = 0 ; d1 < 2 ; d1++ )
        cout<<result[c1][d1]<<"   ";
cout<<endl;
}

return result;
}

int** MultiplyMatrix(int a, int b, int c, int d, int e, int f,int g, int h )
{
int** firstMatrix = new int*[2];
for(int i = 0; i < 2; ++i)
    firstMatrix[i] = new int[2];

int** secondMatrix = new int*[2];
for(int j = 0; j < 2; ++j)
    secondMatrix[j] = new int[2];

int** result = new int*[2];
for(int k = 0; k < 2; ++k)
    result[k] = new int[2];

int c1, k1, d1;
int sum=0;
firstMatrix[0][0]=a;
firstMatrix[0][1]=b;
firstMatrix[1][0]=c;
firstMatrix[1][1]=d;

secondMatrix[0][0]=e;
secondMatrix[0][1]=f;
secondMatrix[1][0]=g;
secondMatrix[1][1]=h;
		
for (c1 = 0 ; c1 <2; c1++ )
{
   for (d1 = 0 ; d1 < 2 ; d1++ )
   {
      for (k1 = 0 ; k1 < 2 ; k1++ )
      {
          sum = sum + firstMatrix[c1][k1]*secondMatrix[k1][d1];
      }
 
      result[c1][d1] = sum;
      sum = 0;
   }
}
 

for ( c1 = 0 ; c1 < 2 ; c1++ )
{
  for ( d1 = 0 ; d1 < 2 ; d1++ )
	cout<<result[c1][d1]<<"   ";
cout<<endl;
}
  
for(int i = 0; i < 2; ++i) 
{
    delete [] firstMatrix[i];
}
delete [] firstMatrix;
  
return result;
}

int main()
{
Matrix m;
 m.MultiplyMatrix(2, 2, 2, 2,2,2,2,2);
}
